package jdbc;

import java.sql.*;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();

        try(Connection connection = DEUtil.getConnection()) {
            Statement statement = connection.createStatement();
            String sql = "SELECT * FROM user WHERE username=? AND password=?;";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,username);
            preparedStatement.setString(2,password);
            ResultSet resultSet = preparedStatement.executeQuery();
            boolean i=resultSet.next()?true:false;
            System.out.println(i?"登录成功":"登录失败");
            if(i){
                System.out.println("登录成功");
            }else{
                System.out.println("登录失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
